package com.ftw.commons.utils

import android.app.Activity
import android.content.Context
import android.content.Context.INPUT_METHOD_SERVICE
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.EditText


/**
 * 描    述：
 * 作    者：fantianwen
 * 时    间：2019-09-21  10:56
 */

object SoftKeyBoardUtils {

    fun hideSoftKeyboard(editText: EditText?, context: Context?) {
        if (editText != null && context != null) {
            val imm = context
                .getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
            imm.hideSoftInputFromWindow(editText.windowToken, 0)
        }
    }

    fun showSoftKeyboard(editText: EditText?, context: Context?) {
        if (editText != null && context != null) {
            val imm = context
                .getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
            imm.showSoftInput(editText, 0)
        }
    }

    fun showOrHide(context: Context, view: View, isVISIBLE: Boolean) {
        val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
        if (isVISIBLE) {
            imm.showSoftInput(view, InputMethodManager.SHOW_FORCED)//SHOW_FORCED表示强制显示
        } else {
            imm.hideSoftInputFromWindow(view.windowToken, 0) //强制隐藏键盘
        }
    }


}